Skip to content

fix(Hex): decode odd-length signed hex and reject unsized negative numbers - #584

Merged
jxom merged 1 commit into
mainfrom
fix/hex-signed-encode-decode
Nov 8, 2026
Merged

jxom merged 1 commit into
mainfrom
fix/hex-signed-encode-decode

Conversation

@jxom

@jxom jxom commented Nov 8, 2026

Copy link
Copy Markdown
Member

Supersedes #439 by @gomesalexandre (credited as co-author).

Fixes two signed-integer bugs in Hex:

  • Hex.toBigInt and Hex.toNumber with signed: true threw a RangeError on odd-length hex (e.g. Hex.toBigInt(Hex.fromNumber(420), { signed: true })), because the byte width came out fractional. The width now comes from Hex.size, which rounds up, so odd-length hex is read as left-padded to whole bytes. That matches Bytes.fromHex and viem (fix: handle odd-length hex in signed hexToBigInt / hexToNumber viem#4913).
  • Hex.fromNumber(-1, { signed: true }) with no size returned 0x0. It now throws IntegerOutOfRangeError, the same as the bigint overload already did. Passing signed without size is already a type error, so only untyped callers see the change.

No other ox caller changes behavior: every internal caller that passes signed also passes size or pads to whole bytes. The new assertions in Hex.test.ts fail without the source change.

…mbers

Hex.toBigInt and Hex.toNumber with signed: true computed a fractional byte
width for odd-length hex and threw a RangeError. Hex.fromNumber with
signed: true and no size let negative numbers through and encoded them as 0x0.

Supersedes #439.

Co-authored-by: gomesalexandre <contact@alexandregomes.fr>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bc8f-2366-769e-b08c-408e9dab25b0
Co-authored-by: jxom <jake@tempo.xyz>
@vercel

vercel Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ox Error Error Nov 8, 2026 7:52pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T19:50:43.733944Z c5591b1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Published ox@0.0.0-pr-584-c5591b1 under the pr-584 dist-tag, which follows this pull request until it closes.

pnpm add ox@pr-584
pnpm add ox@0.0.0-pr-584-c5591b1

@jxom
jxom merged commit 7f37495 into main Nov 8, 2026
15 of 16 checks passed
@jxom
jxom deleted the fix/hex-signed-encode-decode branch November 8, 2026 19:58
@github-actions github-actions Bot mentioned this pull request Nov 8, 2026

This branch had an error being deployed

1 failed deployment
Preview — c5591b10 Deployed Nov 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants